package com.nuanshui.heatedloan.extension.filter;

import java.io.PrintWriter;

import javax.servlet.FilterChain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.web.filter.OncePerRequestFilter;

import redis.clients.jedis.Jedis;

public class TestInterfaceFilter extends OncePerRequestFilter {

 
	@Override
	protected void doFilterInternal(HttpServletRequest request,
			HttpServletResponse response, FilterChain filterChain){
		
		try {
			Jedis jedis = new Jedis("10.0.0.254", 6379);
			
			jedis.auth("Xunbao123");
			jedis.select(5);
			String uri = request.getRequestURI();
			String jsonData = jedis.get("interface_name:"+uri);
			if(StringUtils.isNotEmpty(jsonData)) {
				//response.addHeader("", value);
				PrintWriter out = response.getWriter();
				out.write(jsonData);
				out.close();
				out.close();
				return;
			}
			jedis.close();
			 filterChain.doFilter(request,response);    
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		
	}
}
